# Read in the oil spill and CA shapefiles
ca_oil <- read_sf(here("ds394"), layer = "ds394") %>%
clean_names()
# st_crs(ca_oil)
ca_counties <- read_sf(here("ca_counties"), layer = "CA_Counties_TIGER2016") %>%
clean_names() %>%
select(name)
# st_crs(ca_counties)
# Make exploratoy map to show where the CA oil spills have been
ggplot() +
geom_sf(data = ca_counties, fill = "wheat") +
geom_sf(data = ca_oil,
color = "deepskyblue4",
alpha = 0.3,
size = 1.2) +
theme_minimal() +
labs(x = "Latitude",y = "Longitude", title = "Oil Spill Incidents in California")
Figure 1: Each point on this map of Californiarepresents a specific oil spill incident from 2008 (Data: CA DFW Oil Spill Incident Tracking, 2008).
tmap_mode("view")
tm_shape(ca_oil) +
tm_dots(aes(color = "blue"))
# Join together
ca_oil_inland <- ca_counties %>%
st_join(ca_oil_subset)
# Get counts of inland oil spill events
oil_counts <- ca_oil_inland %>%
count(name.x)
# Make a chloropleth map in ggplot
# fill color depends on count of inland oil spill events by county
ggplot(data = oil_counts) +
geom_sf(aes(fill = n), color = "black", size = 0.1) +
scale_fill_gradientn(colors = c("lightgrey", "aquamarine", "cyan", "deepskyblue","navy")) +
theme_minimal() +
labs(x = "Latitude", y = "Longitude", title = "Chloropleth Map of Oil Spill Incidents in 2008", fill = "Oil Spill Incidents")
Figure 3: The chloropleth map of California reveals which counties had the most oil spill incidents in 2008. The darkest counties are those that had the greatest number of incidents (Data: CA DFW Oil Spill Incident Tracking, 2008).